#include <stdio.h>

typedef int int_2[3];
typedef float float_3[3];

int times_int(int a,int b,int c) {
	return a*b*c;
}

float times_float(float a,float b, float c) {
	return a*b*c;
}

int determinant(int mat[2][2]) {
	return mat[0][0]*mat[1][1]-mat[0][1]*mat[1][0];
}

int faculteit(int a);

void main() {
	printf("With forward declaration: faculteit van 5 = %i\n",faculteit(5));
	printf("Explicit cast: (int)4.4*(int)4.4 = %i\n",(int)4.4*(int)4.4);
	printf("Explicit cast: (int)4.4*4.4 = %f\n",(int)4.4*4.4);

	int i[3] = {1,2,3};
	float f[3] = {1.1,2.2,3.3};
	
	printf("%i * %i * %i = %i\n",i[0],i[1],i[2],times_int(i[0],i[1],i[2]));
	printf("%1f * %2f * %3f = %4f\n",f[0],f[1],f[2],times_float(f[0],f[1],f[2]));
	
	int k = 1;
	int array[2][2] = {1,2,3,4};
	printf("Should print 3: %i\n",array[k][0]);
	
	
	printf("Enter i[0]: ");
	scanf("%i",i[0]);
	printf("Enter i[1]: ");
	scanf("%i",i[1]);
	printf("Enter i[2]: ");
	scanf("%i",i[2]);
	printf("Enter f[0]: ");
	scanf("%f",f[0]);
	printf("Enter f[1]: ");
	scanf("%f",f[1]);
	printf("Enter f[2]: ");
	scanf("%f",f[2]);
	
	printf("%i * %i * %i = %i\n",i[0],i[1],i[2],times_int(i[0],i[1],i[2]));
	printf("%5f * %6f * %7f = %8f\n",f[0],f[1],f[2],times_float(f[0],f[1],f[2]));
	
	printf("10/1.66 = %f\n",10/1.66);
	printf("10 mod 6 = %i\n",10%6);
	printf("99.99 - 43 = %i\n",99.99-43);
	printf("(1+2)*3=%i\n",(1+2)*3);
	
	float floatvar=5.33;
	int intvar=floatvar;
	printf("Type conversion: converting 5.33 to int: %i\n",intvar);
	
	float b=4.4;
	int a = b!=4.4?4.4*4.4:3.4*3.4;
	printf("a should be 11, a = %i\n",a); 
	
	int one = 1;
	int zero = 0;
	
	if(one==one && zero==zero) {
		printf("This should be printed (IF)\n");
		if(1==4 || 3==3) {
			printf("This should be printed (Nested IF)\n");
		} else {
			printf("This should not be printed.\n");
		}
	} else {
		printf("This should not be printed.\n");
	}
	
	if(one > zero) {
		printf("This should be printed (>)\n");
	}
	
	if(zero < one) {
		printf("this should be printed (<)\n");
	}
	
	if(zero<=one) {
		printf("this should be printed (<=)\n");
	}
	
	if(one>=zero) {
		printf("this should be printed (>=)\n");
	}
	
	if(zero!=zero) {
		
	} else {
		printf("this should be printed (!=)\n");
	}
	
	if(one) {
		printf("this should be printed (singular stmt)\n");
	}
	
	if(!zero) {
		printf("This should be printed (!)\n");
	}
	
	printf("Negation test: 5*-4 = %i\n",5*-4);
	
	int x = 3;
	printf("x should be printed three times\n");
	while(x > 0) {
		printf("x");
		x = x-1;
	}
	printf("\n");
	
	
	printf("x should be printed once, y should not be printed\n");
	while(one==one) {
		printf("x\n");
		int temp = 1;
		while(temp > 0) {
			temp = temp-1;
			continue;
			printf("x\n");
		}
		break;
		printf("y\n");
	}
	
	printf("Initializing matrix\n1 2\n3 4\n");
	int mat[2][2];
	mat[0][0] = 1;
	mat[0][1] = 2;
	mat[1][0] = 3;
	mat[1][1] = 4;
	printf("Determinant is: %i\n",determinant(mat));
	
	int xxx=6;
	int nested_square(int a) {
		int xxx=5;
		printf("xxx should be 5: %i\n",xxx);
		return a*a;
	}
	printf("xxx should be 6: %i\n",xxx);
	int square = nested_square(5);
	printf("Square of 5 = %i\n",square);
	
	char scantext[20];
	printf("Enter a string: ");
	scanf("%s",scantext);
	printf("This is what you entered: %s\n",scantext);	
}

int faculteit(int a) {
	if(a > 1) {
		return a*faculteit(a-1);
	}
	return 1;
}